//
//  TNST_FindFriendVC.m
//  CollTest
//
//  Created by codew on 12/30/21.
//

#import "TNST_FindFriendVC.h"

#define angle2Radion(angle) @(angle / 180.0 * M_PI)

@interface TNST_FindFriendVC ()

@property (weak, nonatomic) IBOutlet UIImageView *imageBG1;

@end

@implementation TNST_FindFriendVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self animCC5];
}

- (void)animCC
{
    CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
    
    anim.keyPath = @"position";
    
    
    
    NSValue *value = [NSValue valueWithCGPoint:CGPointMake(10, 10)];
//    NSValue *value1 = [NSValue valueWithCGPoint:CGPointMake(10, 10)];;
//    NSValue *valu2 = [NSValue valueWithCGPoint:CGPointMake(10, 10)];;
    anim.values = @[value];//,value1,valu2];
    
    anim.fillMode = kCAFillModeForwards;
    anim.removedOnCompletion = NO;
    
    anim.duration = 10;
    anim.repeatCount = MAXFLOAT;
    _imageBG1.layer.transform;
    [_imageBG1.layer addAnimation:anim forKey:nil];
}

- (void)animCC1
{
    CABasicAnimation * base = [CABasicAnimation animationWithKeyPath:@"position.y"];
        //起始点
        base.fromValue =@(-self.view.bounds.size.width/2);
        //结束点
        base.toValue = @(self.view.bounds.size.width/2) ;
        //时间间隔
        base.duration = 4;
       //决定当前对象在非active时间段的行为.比如动画开始之前,动画结束之后
        base.fillMode = kCAFillModeBoth;
        base.delegate = self;
       [self.imageBG1.layer addAnimation: base forKey:nil];
}

- (void)animCC2
{
    CAKeyframeAnimation * rotate = [CAKeyframeAnimation animationWithKeyPath:@"position.y"];
      rotate.duration = 4;   //时间间隔
      rotate.repeatCount = MAXFLOAT;   //重复次数
      rotate.values =  @[@0, @10, @30, @50];    //关键帧数组
//      rotate.keyTimes = @[@0,@0.25,@0.5,@0.75,@1.0];             //关键帧时间点数组
      [self.imageBG1.layer addAnimation:rotate forKey:nil];
}


- (void)animCC3
{
    
    CABasicAnimation  *basic = [CABasicAnimation animationWithKeyPath:@"position.y"];
     // key:表示你想让它产生那个属性的动画,    position界面的移动使用
    basic.toValue = [NSValue valueWithCGPoint:CGPointMake(0,-950)];  // 移动的位置
//    basic.byValue = [NSValue valueWithCGPoint:CGPointMake(0, 50)];
    //时间间隔
    basic.duration = 0.1;
    basic.removedOnCompletion = NO;   // 到了那个移动位置后,是否返回
    basic.fillMode = kCAFillModeForwards;// 动画的阶段模式,在动画还没开始前  和上面的一起搭配使用,固定用法
        //关键帧时间点数组
      [self.imageBG1.layer addAnimation:basic forKey:nil];
}

- (void)animCC4
{
//
//    CAKeyframeAnimation  *basic = [CAKeyframeAnimation animationWithKeyPath:@"position.y"];
//     // key:表示你想让它产生那个属性的动画,    position界面的移动使用
//    basic.toValue = [NSValue valueWithCGPoint:CGPointMake(0, 50)];  // 移动的位置
////    basic.byValue = [NSValue valueWithCGPoint:CGPointMake(0, 50)];
//    //时间间隔
//    basic.duration = 4;
//    basic.removedOnCompletion = NO;   // 到了那个移动位置后,是否返回
//    basic.fillMode = kCAFillModeForwards;// 动画的阶段模式,在动画还没开始前  和上面的一起搭配使用,固定用法
//        //关键帧时间点数组
//      [self.imageBG1.layer addAnimation:basic forKey:nil];
    
    
    
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position.y"];
    
    animation.values = @[
        @(ScreenWidth*0.5+10), @(ScreenWidth*0.5+20), @(ScreenWidth*0.5+30),
        
//        @(ScreenWidth*0.5+20), @(ScreenWidth*0.5+10), @(ScreenWidth*0.5+0),
        
//        @(ScreenWidth*0.5-10), @(ScreenWidth*0.5-20), @(ScreenWidth*0.5-30),
    ];
    animation.duration = 3.0f;
    
    animation.repeatCount = MAXFLOAT;
    animation.fillMode = kCAFillModeForwards;
    animation.removedOnCompletion = NO;
    animation.autoreverses = YES;
    [self.imageBG1.layer addAnimation:animation forKey:@"animation"];
    
//        self.imageBG1.speed = 0;
}


- (void)animCC5
{
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation"];
    // 动画选项设定
    animation.duration = 2; // 动画持续时间
    animation.repeatCount = HUGE; // 重复次数无限次HUGE
    animation.autoreverses = YES; //（重点设置为NO闪回）// 动画结束时执行逆动画
    // 起始点
    animation.fromValue = [NSValue valueWithCGPoint:CGPointMake(0, -30)]; // 开始时坐标
    animation.toValue = [NSValue valueWithCGPoint:CGPointMake(0, 0)]; // 结束时的坐标
    animation.removedOnCompletion = NO;
    // 添加动画
    [self.imageBG1.layer addAnimation:animation forKey:@"translation"];
    
    
    
    
    
    
    
}


- (void)animCC6
{
    CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
    
    anim.values = @[angle2Radion(-180),angle2Radion(180),angle2Radion(-180)];
    anim.keyPath = @"transform.rotation";
    
    
    
    // 动画选项设定
    anim.duration = 2; // 动画持续时间
    anim.repeatCount = HUGE; // 重复次数无限次HUGE
    anim.autoreverses = YES; //（重点设置为NO闪回）// 动画结束时执行逆动画
    
    [self.imageBG1.layer addAnimation:anim forKey:nil];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.imageBG1.layer removeAllAnimations];
    
    [self animCC3];
}


@end
